<html>
<head>
<title>firstworks   Programming with SQL Relay using ODBC</title>
<link href="../css/styles.css" rel="stylesheet">
</head>
<body>

<span class="heading1">Programming with SQL Relay using ODBC</span><br><br>

<p>The SQL Relay distribution provides an <b>experimental</b> ODBC driver.  The
driver is incomplete, may only be used with iODBC or unixODBC, and is
<b>NOT</b> supported on Windows, but may be experimented with and may be useful
for some simple programs.</p>

<p>With iODBC or unixODBC, you can create a DSN for SQL Relay just like you
would for any other database by editing /etc/odbc.ini and adding an entry 
like the following:</p>

<blockquote>
<pre>
<font color="#6a5acd">[sqlrtest]</font>
<font color="#2e8b57"><b>Driver=</b></font>/usr/local/firstworks/lib/libsqlrodbc.so
<font color="#2e8b57"><b>SERVER=</b></font>localhost
<font color="#2e8b57"><b>PORT=</b></font>8006
<font color="#2e8b57"><b>DATABASE=</b></font>testdb
<font color="#2e8b57"><b>USER=</b></font>testuser
<font color="#2e8b57"><b>PASSWORD=</b></font>testpass
</pre>
</blockquote>

<p>Now you can use the <i>isql</i> command line utility that comes with iODBC
or unixODBC to access the database through SQL Relay as follows:</p>

<blockquote>
<b>isql sqlrtest</b>
</blockquote>

<p>Here is a sample session:</p>

<blockquote>
<pre>
<font color="#a52a2a"><b>[</b></font>mused@localhost /home/mused<font color="#a52a2a"><b>]</b></font>$ isql sqlrtest
+---------------------------------------+
<font color="#a52a2a"><b>|</b></font>&nbsp;Connected<font color="#a52a2a"><b>!</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>|</b></font>
<font color="#a52a2a"><b>|</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>|</b></font>
<font color="#a52a2a"><b>|</b></font>&nbsp;sql-statement&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>|</b></font>
<font color="#a52a2a"><b>|</b></font>&nbsp;help <font color="#a52a2a"><b>[</b></font>tablename<font color="#a52a2a"><b>]</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>|</b></font>
<font color="#a52a2a"><b>|</b></font>&nbsp;quit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>|</b></font>
<font color="#a52a2a"><b>|</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>|</b></font>
+---------------------------------------+
SQL<font color="#a52a2a"><b>&gt;</b></font>&nbsp;create table <font color="#a52a2a"><b>test</b></font>&nbsp;<font color="#a52a2a"><b>(</b></font>col1 varchar<font color="#a52a2a"><b>(</b></font><font color="#ff00ff">20</font><font color="#a52a2a"><b>))</b></font><font color="#a52a2a"><b>;</b></font>
SQLRowCount returns <font color="#ff00ff">0</font>
SQL<font color="#a52a2a"><b>&gt;</b></font>&nbsp;insert into <font color="#a52a2a"><b>test</b></font>&nbsp;values <font color="#a52a2a"><b>(</b></font><font color="#a52a2a"><b>'</b></font><font color="#ff00ff">hello</font><font color="#a52a2a"><b>'</b></font><font color="#a52a2a"><b>)</b></font><font color="#a52a2a"><b>;</b></font>
SQLRowCount returns <font color="#ff00ff">1</font>
SQL<font color="#a52a2a"><b>&gt;</b></font>&nbsp;insert into <font color="#a52a2a"><b>test</b></font>&nbsp;values <font color="#a52a2a"><b>(</b></font><font color="#a52a2a"><b>'</b></font><font color="#ff00ff">bye</font><font color="#a52a2a"><b>'</b></font><font color="#a52a2a"><b>)</b></font><font color="#a52a2a"><b>;</b></font>
SQLRowCount returns <font color="#ff00ff">1</font>
SQL<font color="#a52a2a"><b>&gt;</b></font>&nbsp;select * from <font color="#a52a2a"><b>test</b></font><font color="#a52a2a"><b>;</b></font>
+-----------+
<font color="#a52a2a"><b>|</b></font>&nbsp;col1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>|</b></font>
+-----------+
<font color="#a52a2a"><b>|</b></font>&nbsp;hello&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>|</b></font>
<font color="#a52a2a"><b>|</b></font>&nbsp;bye&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>|</b></font>
+-----------+
SQLRowCount returns <font color="#ff00ff">0</font>
<font color="#ff00ff">2</font>&nbsp;rows fetched
SQL<font color="#a52a2a"><b>&gt;</b></font>&nbsp;quit<font color="#a52a2a"><b>;</b></font>
</pre>
</blockquote>

<p>Similarly, any program that uses ODBC can be configured to use SQL Relay via
ODBC by setting its DSN to the SQL Relay DSN defined in /etc/odbc.ini.</p>

<p>Developing applications which use ODBC is beyond the scope if this document
but many examples and tutorials may be found on the web.</p>

</body>
</html>
